'use strict'

define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 
        'modalSearch', 'datetimepicker', 'datetimepickerCN', 'shiftform'], function ($) {
  
  return {
  
    init: function () {
      this.initCreate();
      this.initVehicle();
    },
    
    initCreate: function() {
      
      $(document).find('form[data-validate="true"]').bt_validate()  //bind validate
      
      var $form = $(document).find('form');                          //bind shiftform
      $form.shiftform({
        beforeSubmit: function (el) {
          $form.trigger("validate.ajax.submit");
          return $.bt_validate.result[$.bt_validate.form_id]
        }
      })
      
    },
    
    initVehicle: function() {
      
      $('[data-target="#modal-search-vehicle"]').modalsearch({
        url: function(){
          var url = window.__CTX__.root + '/vehicles/query';
          return url + '?companyIds=' + $('input[name="companyId"]').val();
        },
        tableColumns: ['驳运车代码', '驳运车名称'],
        tableValues: ['code', 'name'],
        displayValues: ['code', 'name'],
        values: ['id']
      });
      
      var options = {
        time: 1000,
        url: window.__CTX__.root + "/vehicles/query",
        queryName: "code",
        value: ["id"],
        display: ["code", "name"]
      }
      $('.vehicle-search').koalaSearch(options);

    }
  
  }
  
})